package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.constant.SysConstant;
import com.jianyun.jyzs.dao.ItemModel;

import java.util.List;

public class OAAreaAdapter extends BaseAdapter{
    private Context context;
    List<ItemModel> list;//存放图标及消息提醒

    public OAAreaAdapter(Context context, List<ItemModel> list) {
        this.context = context;
        this.list = list;
    }

    public void setList(List<ItemModel> ls) {
        if (ls.size()%4==0){
            this.list = ls;
        }else {
            int i = 4-ls.size()%4;
            for (int j =0;j<i;j++){
                ls.add(null);
            }
        }
        this.list = ls;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = View.inflate(context, R.layout.item_app_view, null);
        ItemModel messageVO = list.get(position);
        if (messageVO!=null){
            ImageView iv_msgImg = (ImageView) convertView.findViewById(R.id.ItemImage);
            TextView tv_unRead = (TextView) convertView.findViewById(R.id.tv_unRead);
            TextView tv_text = (TextView) convertView.findViewById(R.id.ItemText);
            iv_msgImg.setImageResource(SysConstant.menu_list[position]);
            tv_text.setText(messageVO.getTitle());
//            if(messageVO.isShow){
//                tv_unRead.setVisibility(View.VISIBLE);
//                tv_unRead.setText(messageVO.count+"");
//            }else{
//                tv_unRead.setVisibility(View.GONE);
//            }

            if (!messageVO.isUnRead()){
                tv_unRead.setVisibility(View.GONE);
            }else {
                tv_unRead.setVisibility(View.VISIBLE);

            }

        }else {
            convertView.setBackgroundResource(R.drawable.app_content_bg_null);
        }
        return convertView;
    }


}